﻿@{
    ViewBag.Title = "角色用户";
    Layout =  null;
}
<style>
    input[type="checkbox"] {
        border: 1px solid #C6C6C6;
        outline: none;
    }

    .button {
        border-radius: 0px;
    }

    .mainbody {
        padding: 0px;
    }
    /*自定义复选框*/
    .ScrollBar {
        background: none repeat scroll 0 0 #fff;
        overflow: auto;
    }

    .sys_spec_text {
        padding-left: 15px;
    }

        .sys_spec_text li {
            display: inline;
            float: left;
            height: 43px;
            margin: 10px 15px 0px 0;
            outline: none;
            outline: none;
            position: relative;
            position: relative;
        }

            .sys_spec_text li a {
                background: #fff;
                border: 1px solid #ccc;
                border-radius: 5px 5px 5px 5px;
                cursor: pointer;
                display: inline-block;
                line-height: 39px;
                outline: none;
                overflow: hidden;
                padding: 0px 0px;
                text-align: center;
                text-align: center;
                text-overflow: ellipsis;
                vertical-align: middle;
                white-space: nowrap;
                width: 98px;
                word-break: keep-all;
            }

                .sys_spec_text li a:hover {
                    border: 1px solid #4A5B79;
                    padding: 0 0px;
                    text-decoration: none;
                }

            .sys_spec_text li .check {
                background: url(/Contents/images/edit/sys_item_selected.gif) no-repeat right bottom;
                bottom: 2px;
                display: none;
                font-size: 0;
                height: 10px;
                line-height: 0;
                position: absolute;
                right: 1px;
                width: 10px;
                z-index: 99;
            }

            .sys_spec_text li.selected a {
                border: 1px solid #4A5B79;
                padding: 0 0px;
            }

            .sys_spec_text li.selected .check {
                display: block;
            }

            .sys_spec_text li img {
                border: 0px solid #fff;
                margin-top: -2px;
                padding-right: 5px;
                vertical-align: middle;
            }

        .sys_spec_text a.disabled {
            color: #a9a6a6;
            cursor: not-allowed;
            display: block;
            overflow: hidden;
        }
</style>
    
@model IList<EIP.System.Models.Dtos.Identity.SystemChosenUserOutput>
                <div class="alert alert-warning  alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    选中复选框即可授予相应权限，取消选中则回收相应权限。
                </div>

<section class="content" id="mainDiv">
    <div class="row">
        <div class="col-md-4">
            <div class="box box-primary box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">组织机构</h3>
                    <div class="box-tools pull-right">
                        <a href="javascript:void(0);" onclick=" arrowin(); return false; " data-toggle="tooltip" title="展开" class="btn btn-default btn-sm"><i class="fa fa-folder-open" id="arrowin">展开</i></a>
                    </div>
                </div>
                <div class="box-body">
                    @*工具条*@
                    <ul id="chosenPrivilegeMasterUserTree" class="ztree" style="height: 370px; overflow: auto"></ul>
                </div>
            </div>
        </div>
        <div class="col-md-8">
            <div class="box box-primary box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">人员</h3>
                   
                </div>
                <div class="box-body no-padding">
                    @*所有功能性按钮*@
                    <div style="height: 383px;" class="ScrollBar">

                        <ul id="AccessButton" class="sys_spec_text">
                            @{
    foreach (var m in Model)
    {
        string className = m.Exist ? "selected" : "";
        <li title="@m.Code-@m.Name"  searchcode="@m.Code.ToLower()" searchname="@m.Name.ToLower()" name="@m.OrganizationId" class="@className">
            <a id="@m.UserId">
                @m.Name
            </a><i class="check"></i>
        </li>
    }
}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

</section>
                <div class="box-footer text-right">
                    <!--以下两种方式提交验证,根据所需选择-->
                    <button onclick=" formSubmit(); return false; " type="button" class="btn btn-success" data-btn-type="save" title="确定"><span class="bootstrap-dialog-button-icon fa fa-check"></span>确定</button>
                    <button type="button" class="btn btn-danger" data-btn-type="cancel" data-dismiss="modal"><span class="bootstrap-dialog-button-icon fa fa-times"></span>取消</button>
                </div>
                @Html.Hidden("privilegeMasterValue")
                @Html.Hidden("privilegeMaster")
<script>
    $(function () {
        loadChosenPrivilegeMasterUserTree();
        initEvent();
    });

    var chosenPrivilegeMasterUserzNodes,
        chosenPrivilegeMasterUserTreeObj,
        chosenPrivilegeMasterUserTreeSetting;
       

    //表单提交
    function formSubmit() {
        var users = $("li[class='selected']", $(".ScrollBar")).find("a");
        var json = "";

        $.each(users, function (i, item) {
            json += "{\"u\":\"" + item.id + "\"},";
        });
        json = json.substring(0, json.length - 1);
        json = "[" + json + "]";

        UtilAjaxPostWait("/Common/UserControl/SavePrivilegeMasterUser",
            {
                privilegeMasterUser: json,
                privilegeMasterValue: $("#privilegeMasterValue").val(),
                privilegeMaster:$("#privilegeMaster").val()
            },
            success);
    }

    //提交成功
    function success(data) {
        if (DialogAjaxResult(data)) {
            getPrivilegeMasterUserGridData();
        }
    }

    //初始化组织机构
    function initChosenPrivilegeMasterUserTree() {
        //配置
        chosenPrivilegeMasterUserTreeSetting = {
            view: {
                dblClickExpand: false,
                showLine: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            expandSpeed: "",
            callback: {
                onClick: onClickChosenPrivilegeMasterUserTree
            }
        };
    }

    //初始化树结构:同步
    function initChosenPrivilegeMasterUserTreeData() {
        UtilAjaxPostAsync("/System/Organization/GetOrganizationTree", null, function (data) {
            chosenPrivilegeMasterUserzNodes = data;
            chosenPrivilegeMasterUserTreeObj = $.fn.zTree.init($("#chosenPrivilegeMasterUserTree"), chosenPrivilegeMasterUserTreeSetting, chosenPrivilegeMasterUserzNodes);
        });
    }

    //树点击触发
    function onClickChosenPrivilegeMasterUserTree(e, treeId, treeNode) {
        searchUserByOrgId(treeNode.id);
        //展开或者关闭该节点
        chosenPrivilegeMasterUserTreeObj.expandNode(treeNode);
    }

    //根据组织机构id查询对应的人员信息
    function searchUserByOrgId(orgId) {
        $(".ScrollBar li").hide();
        $("[name='" + orgId + "']").show();
    }

    //折叠/展开
    var expand = false;

    function arrowin() {
        if (expand) {
            chosenPrivilegeMasterUserTreeObj.expandAll(false);
            expand = false;
            $("#arrowin").html("展开").attr("class", "fa fa-folder-open");
            $("#arrowin").parent().attr("title", "展开");
        } else {
            chosenPrivilegeMasterUserTreeObj.expandAll(true);
            expand = true;
            $("#arrowin").html("折叠").attr("class", "fa fa-folder");
            $("#arrowin").parent().attr("title", "折叠");
        }
    }

  

    //加载页面数据
    function loadChosenPrivilegeMasterUserTree() {
        initChosenPrivilegeMasterUserTree();
        initChosenPrivilegeMasterUserTreeData();
        $(".ScrollBar li").show();
    }

    //初始化事件
    function initEvent() {
        $("#AccessButton li").click(function () {
            if (!$(this).hasClass("selected")) {
                $(this).attr("class", "selected");
            } else {
                $(this).attr("class", "");
            }
        });
    }

    //查询
    function search() {
        var key = $("#txtKeywords").val().toLocaleLowerCase();
        if (key != "") {
            $(".ScrollBar li").hide();
        } else {
            $(".ScrollBar li").show();
        }
        $("[searchcode*='" + key + "']", $(".ScrollBar")).show();
        $("[searchname*='" + key + "']", $(".ScrollBar")).show();
    }

    //全选/重置
    var checkAll = true;
    function selectall() {
        var treeNode = ZtreeGetSelectedNodes($.fn.zTree.getZTreeObj("chosenPrivilegeMasterUserTree"));
        var $module = $("li[modelid='" + treeNode[0].id + "']");
        if (checkAll) {
            $module.attr("class", "selected");
            checkAll = false;
        } else {
            $module.attr("class", "");
            checkAll = true;
        }
    }
</script>